package com.example.cloud.service.finance.impl;

import com.example.cloud.dao.finance.PrintConfigDao;
import com.example.cloud.model.finance.PrintConfig;
import com.example.cloud.service.finance.PrintConfigService;
import com.example.cloud.utils.BusinessUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by wt on 2017/4/9.
 */
@Service("printConfigService")
public class PrintConfigServiceImpl implements PrintConfigService {

    @Autowired
    private PrintConfigDao printConfigDao;

    @Override
    public PrintConfig findOne(Long accountId, String code) {
        return printConfigDao.findByAccountIdAndUniqueCode(accountId, code);
    }

    @Override
    @Transactional
    public PrintConfig saveOrUpdate(PrintConfig config) {
        PrintConfig printConfig = printConfigDao.findByAccountIdAndUniqueCode(config.getAccountId(), config.getUniqueCode());
        if(printConfig != null){
            printConfigDao.delete(printConfig);
        }
        BusinessUtil.appendRecord(config);
        return printConfigDao.save(config);
    }
}
